package ldh.im.fxgui.service;

import ldh.im.dto.base.Dto;
import ldh.rpc.util.JsonUtil;
import ldh.rpc.Receive;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReceiveService implements Receive<Dto> {

    private Logger LOGGER = LoggerFactory.getLogger(ReceiveService.class);

    @Override
    public void receive(Dto data) {
        try {
//            if (data instanceof ServerRedirectMessage) {
//                ServerRedirectMessage serverRedirectMessage = (ServerRedirectMessage) data;
//                Object p2pObjectMessage = serverRedirectMessage.getMessage();
//                MessageReceiveHandleFactory.getInstance().getMessageReceiveHandle(p2pObjectMessage.getClass()).handleMessage(p2pObjectMessage);
//            } else if (data instanceof ServerRedirectMessages) {
//                List<MessageObject> p2pObjectMessages = ((ServerRedirectMessages) data).getContent();
//                for (MessageObject p2gObjectMessage : p2pObjectMessages) {
//                    MessageReceiveHandleFactory.getInstance().getMessageReceiveHandle(p2gObjectMessage.getClass()).handleMessage(p2gObjectMessage);
//                }
//            } else if (data instanceof ServerCommonMessage){
//                ServerCommonMessage serverCommonMessage = (ServerCommonMessage) data;
//                Object p2pObjectMessage = serverCommonMessage.getContent();
//                MessageReceiveHandleFactory.getInstance().getMessageReceiveHandle(p2pObjectMessage.getClass()).handleMessage(p2pObjectMessage);
//            } else {
//                throw new RuntimeException("不支持这种数据类型" + data.getClass());
//            }
            LOGGER.info("receive {}", JsonUtil.toJson(data));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
